var api = require('../../utils/api.js')
var util = require('../../utils/util.js');
var app = getApp();


Page({

  /**
   * 页面的初始数据
   */
  data: {
    isServer: false,
    hiddenSPFR: true,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var accountInfo = app.globalData.accountInfo;
    // type 3：是商家   4：服务人员账号
    // shop_type_id 1：餐饮店   2：烟酒店
    // 分润表 、服务员管理， 只有商家有
    if (accountInfo.type == 3) {
      this.setData({
        hiddenSPFR: false,
        isHiddenForeman: false,
        isServer: false,
      })
    }
    if (accountInfo.type == 3 || accountInfo.type == 4) {

      if (accountInfo.type == 3 || (accountInfo.type == 4 && accountInfo.is_open == 2)) { //商家+有看门权限的服务员可现实订单记录
        var hiddenOrderRecord = false;
      } else {
        var hiddenOrderRecord = true;
      }
      if ((accountInfo.shop_type_id == 2 && accountInfo.type == 3) || (accountInfo.type == 4 && accountInfo.discount == 2 && accountInfo.shop_type_id == 2)) { //烟酒店商家（3）+有打折权限的服务员discount1：无打折权限  2：有打折权限
        var hiddenOrderM = true;
      } else {
        var hiddenOrderM = true;
      }
      if (accountInfo.type == 4) {
        var isServer = true;
      } else {
        var isServer = false;
      }

      this.setData({
        hiddenOrderRecord: hiddenOrderRecord,
        hiddenOrderM: hiddenOrderM,
        isServer: isServer
      })

    } else {
      this.setData({
        isHiddenForeman: true,
      })
    }
    var phoneResult = accountInfo.mobile.substring(0, 3) + "****" + accountInfo.mobile.substr(7, 4);
    var avatarUrlReulst = accountInfo.avatar;

    this.setData({
      avatarUrl: avatarUrlReulst,
      phone: phoneResult,
			accountInfo: accountInfo
    })
  },

  // 联系客服
  server_clicked: function(e) {
    wx.makePhoneCall({
      phoneNumber: app.globalData.service_phone
    })
  },


  //店员管理
  invite_clicked: function(e) {
    wx.navigateTo({
      url: 'serviceManage/serviceManage',
    })
  },

	ticket_clicked:function(e){
		wx.navigateTo({
			url: '/pages/mealTicketVerificationRecord/mealTicketVerificationRecord',
		})
	},


  // 退出登录
  logout_Clicked: function(e) {
    var that = this;
    wx.showActionSheet({
      itemList: ['确定'],
      success: function(res) {
        if (res.tapIndex == 0) {
          that.logoutAction();
        }
      }
    })
  },

  order_pay_clicked: function() {
    wx.navigateTo({
      url: '../classification/classification',
    })
  },

  // 退出登录
  logoutAction: function() {
    util.showLoading("退出中...");
    app.globalData.loginState = 2;
    wx.removeStorageSync('isLogin');
    app.globalData.accountInfo = {};
    setTimeout(function () {
      wx.reLaunch({
        url: '../beforeLogin/beforeLogin?login_error_code=11906',
      })
    }, 1000);
  },

  //去酒掌柜用户版
  jiuzhanggui: function() {
    wx.navigateToMiniProgram({
      appId: 'wx2f5360b509c07b8a',
      path: 'pages/index/index',
      envVersion: 'trial', //develop	开发版 trial	体验版  release	正式版
    })
  }
})